package com.redepronik.negosys.rrhh.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.validator.constraints.Length;

import com.redepronik.negosys.invfac.entity.Ingreso;

/**
 * The persistent class for the proveedor database table.
 * 
 */
@Entity
@Table(schema = "rrhh", name = "proveedor")
@NamedQuery(name = "Proveedor.findAll", query = "SELECT p FROM Proveedor p")
public class Proveedor implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(allocationSize = 1, name = "PROVEEDOR_PROVEEDORID_GENERATOR", sequenceName = "RRHH.PROVEEDOR_PROVEEDORID_SEQ")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PROVEEDOR_PROVEEDORID_GENERATOR")
	@Column(unique = true, nullable = false)
	private Integer proveedorid;

	@Column(nullable = false)
	private Boolean activo;

	@Column(length = 10)
	private String folio;

	@Length(min = 3, max = 150, message = "EL CAMPO NOMBRE COMERCIAL ACEPTA DE 3 A 150 LETRAS")
	@Column(nullable = false, length = 150)
	private String nombrecomercial;

	// bi-directional many-to-one association to Persona
	@OneToOne
	@JoinColumn(name = "personaid", nullable = false)
	private Persona persona;

	// bi-directional many-to-one association to Ingreso
	@OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, mappedBy = "proveedor")
	private List<Ingreso> ingresos;

	public Proveedor() {
	}

	public Ingreso addEgreso(Ingreso ingreso) {
		getIngresos().add(ingreso);
		ingreso.setProveedor(this);

		return ingreso;
	}

	public Boolean getActivo() {
		return this.activo;
	}

	public String getFolio() {
		return this.folio;
	}

	public List<Ingreso> getIngresos() {
		return ingresos;
	}

	public String getNombrecomercial() {
		return this.nombrecomercial;
	}

	public Persona getPersona() {
		return this.persona;
	}

	public Integer getProveedorid() {
		return this.proveedorid;
	}

	public Ingreso removeEgreso(Ingreso ingreso) {
		getIngresos().remove(ingreso);
		ingreso.setProveedor(null);

		return ingreso;
	}

	public void setActivo(Boolean activo) {
		this.activo = activo;
	}

	public void setFolio(String folio) {
		this.folio = folio;
	}

	public void setIngresos(List<Ingreso> ingresos) {
		this.ingresos = ingresos;
	}

	public void setNombrecomercial(String nombrecomercial) {
		this.nombrecomercial = nombrecomercial;
	}

	public void setPersona(Persona persona) {
		this.persona = persona;
	}

	public void setProveedorid(Integer proveedorid) {
		this.proveedorid = proveedorid;
	}
}